The Request class represents a complete configuration of an HTTP request.
It can be passed directly to the fetch() method or used to clone, modify, or retry an existing request.
In Scripting, the Request API behaves similarly to the browser’s Fetch API but adds native extensions, including:
Data type support for request bodiesnew Request(input: string | Request, init?: RequestInit)Creates a new Request instance from either a URL string or an existing Request object.
| Parameter | Type | Description |
|---|---|---|
| input | string |
Request |
| init | RequestInit |
Optional configuration object defining request settings (see below). |
| Property | Type | Description |
|---|---|---|
| url | string |
The full URL of the request. |
| method | string |
The HTTP method (default is "GET"). |
| headers | Headers |
A headers object representing the request headers. |
| body | Data | FormData | string | ArrayBuffer | undefined |
The request body, used only for non-GET and non-HEAD requests. |
| allowInsecureRequest | boolean |
Whether to allow plain HTTP requests (default false). |
| handleRedirect | (newRequest: RedirectRequest) => Promise<RedirectRequest | null> |
Custom redirect handler. Return null to cancel the redirect. |
| shouldAllowRedirect | (newRequest: Request) => Promise<boolean> |
Deprecated legacy redirect handler. |
| timeout | number |
Timeout in seconds. The request will automatically abort after this duration. |
| signal | AbortSignal |
Abort signal from an AbortController, allowing manual cancellation. |
| cancelToken | CancelToken |
Deprecated. Older cancellation mechanism; prefer signal. |
| debugLabel | string |
Optional label displayed in logs for debugging and tracking requests. |
clone(): RequestCreates and returns a copy of the current request. The cloned object can be safely modified (e.g., updating headers or timeout) without affecting the original request.
The RequestInit interface defines configuration options for HTTP requests.
It is used as the second argument to fetch() or the optional configuration object when creating a new Request.
Scripting extends this interface with additional native fields.
| Field | Type | Description | |
|---|---|---|---|
| method | string |
The HTTP method such as "GET", "POST", "PUT", "DELETE". Default: "GET". |
|
| headers | HeadersInit |
Request headers, which can be a Headers object, key-value object { key: value }, or array of [key, value] pairs. |
|
| body | Data | FormData | string | ArrayBuffer |
The request body. Ignored for GET and HEAD requests. |
|
| allowInsecureRequest | boolean |
Allows HTTP requests (insecure). Default: false. |
|
| handleRedirect | (newRequest: RedirectRequest) => Promise<RedirectRequest | null> |
Custom redirect handler. Return null to block redirection. |
|
| shouldAllowRedirect | (newRequest: Request) => Promise<boolean> |
Deprecated. Older redirect callback. | |
| timeout | number |
Request timeout in seconds. Triggers AbortError if exceeded. |
|
| signal | AbortSignal |
Used to abort requests manually through an AbortController. |
|
| cancelToken | CancelToken |
Deprecated cancellation mechanism. Use signal instead. |
|
| debugLabel | string |
A label displayed in the debug log for identifying requests. |
fetch()RequestInit is typically passed as the second parameter to fetch() to configure a network request.
| Class | Description |
|---|---|
Headers |
Manages request headers, used with the headers field. |
Data |
Represents binary data. Can be used as the request body for file uploads or raw bytes. |
FormData |
Builds multipart/form-data bodies for form or file submissions. |
AbortController / AbortSignal |
Enables manual request cancellation. |
CancelToken |
Deprecated cancellation mechanism retained for backward compatibility. |
RedirectRequest |
Represents the redirected request passed to handleRedirect. |
When a request encounters an HTTP redirect, and a handleRedirect callback is defined in the Request or RequestInit object, the system will invoke that callback before following the redirect.
The callback receives a RedirectRequest object, which describes the full details of the redirect request.
You can inspect or modify this object to control whether and how the redirect should proceed.
| Field | Type | Description |
|---|---|---|
| method | string |
The HTTP method for the redirected request (e.g., "GET", "POST"). |
| url | string |
The full target URL of the redirect. |
| headers | Record<string, string> |
The HTTP headers to be sent with the redirect request. You can modify these before proceeding. |
| cookies | Cookie[] |
The list of cookies available for the redirected request (same format as Response.cookies). |
| body | Data (optional) |
The body of the redirect request, if applicable (e.g., for non-GET methods). |
| timeout | number (optional) |
The request timeout in seconds. |
The handleRedirect callback allows you to:
When the callback returns:
RedirectRequest → The redirect proceeds using your modified configuration.null → The redirect is canceled, and the fetch() call resolves with the current response.handleRedirect is not defined, all redirects are automatically followed by default.null from the callback prevents further redirection.redirect.cookies.RedirectRequest (such as headers or method) will be applied before the next request is executed.Request and RequestInit form the foundation of Scripting’s networking system:
Request encapsulates a complete HTTP request and can be reused or cloned.RequestInit defines configuration options for flexible initialization.fetch(), Response, Headers, Data, and FormData.